package userTests;

import org.testng.annotations.Test;
import org.openqa.selenium.*;

public class ExchangeTests extends TestBaseUser {

	@Test
	public void testExchange() {

		openMainPageUser();
		gotoSignInUser();
		LoginLogoutDataUser signIn = new LoginLogoutDataUser();
		signIn.phoneNumber = "955413233";
		signIn.password = "!23Qwe";
		fillSignInUser(signIn);
		submitSignInUser();

		wd.findElement(By.cssSelector("td.pointer")).click();
		wd.findElement(By.id("btnExchange")).click();
		wd.findElement(By.id("amount_integer")).click();
		wd.findElement(By.id("amount_integer")).clear();
		wd.findElement(By.id("amount_integer")).sendKeys("1");
		if (!wd.findElement(
				By.xpath("//form[@id='Bank_PaymentOrder_Form_Exchange']/fieldset/div[3]/div/select//option[4]"))
				.isSelected()) {
			wd.findElement(
					By.xpath("//form[@id='Bank_PaymentOrder_Form_Exchange']/fieldset/div[3]/div/select//option[4]"))
					.click();
		}
		wd.findElement(By.name("preview")).click();
		wd.findElement(By.name("edit")).click();
		wd.findElement(By.id("amount_integer")).click();
		wd.findElement(By.id("amount_integer")).clear();
		wd.findElement(By.id("amount_integer")).sendKeys("5");
		if (!wd.findElement(
				By.xpath("//form[@id='Bank_PaymentOrder_Form_Exchange']/fieldset/div[3]/div/select//option[2]"))
				.isSelected()) {
			wd.findElement(
					By.xpath("//form[@id='Bank_PaymentOrder_Form_Exchange']/fieldset/div[3]/div/select//option[2]"))
					.click();
		}
		wd.findElement(By.name("preview")).click();
		wd.findElement(By.id("payment_password")).click();
		wd.findElement(By.id("payment_password")).clear();
		wd.findElement(By.id("payment_password")).sendKeys("1");
		wd.findElement(By.name("confirm")).click();
		wd.findElement(By.cssSelector("td.pointer")).click();
		wd.findElement(By.id("linkOperationDetails_595")).click();
		wd.findElement(By.cssSelector("button.btn.dialog-close-btn")).click();
		wd.findElement(By.cssSelector("#29 > td.pointer")).click();
		wd.findElement(By.id("linkOperationDetails_599")).click();
		wd.findElement(By.cssSelector("button.btn.dialog-close-btn")).click();
	}

	protected void fillTransferForm() {
		wd.findElement(By.id("amount_integer")).click();
		wd.findElement(By.id("amount_integer")).clear();
		wd.findElement(By.id("amount_integer")).sendKeys("15");
		wd.findElement(By.id("contragent")).click();
		wd.findElement(By.id("contragent")).clear();
		wd.findElement(By.id("contragent")).sendKeys("+");
		wd.findElement(By.id("contragent")).click();
		wd.findElement(By.id("contragent")).clear();
		wd.findElement(By.id("contragent")).sendKeys("+380997047402");
		wd.findElement(By.id("comments")).click();
		wd.findElement(By.id("comments")).clear();
		wd.findElement(By.id("comments")).sendKeys("auto11");
	}

	protected void editTransferForm() {
		wd.findElement(By.id("amount_integer")).click();
		wd.findElement(By.id("amount_integer")).clear();
		wd.findElement(By.id("amount_integer")).sendKeys("11");
		wd.findElement(By.id("contragent")).click();
		wd.findElement(By.id("contragent")).clear();
		wd.findElement(By.id("contragent")).sendKeys("+380999999998");
		wd.findElement(By.id("comments")).click();
		wd.findElement(By.id("comments")).clear();
		wd.findElement(By.id("comments")).sendKeys("q11");
	}

	protected void fillPayPassword() {
		wd.findElement(By.id("payment_password")).click();
		wd.findElement(By.id("payment_password")).clear();
		wd.findElement(By.id("payment_password")).sendKeys("1");
	}

	
	
}
